﻿Imports SIGI.Common.BE

Public Class UC_AppointmentPreview

#Region "<< -Attributes- >>"
    Private _Appointment As AppointmentBE = Nothing
#End Region

#Region "<< -Events- >>"
    Private Sub UC_AppointmentPreview_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim wStartHour As String = String.Empty
        Dim wEndHour As String = String.Empty
        Dim wSubject As String = String.Empty
        Dim wMin As Integer = 0

        If Me.DesignMode OrElse _Appointment Is Nothing Then Return

        'wMin = Math.Min(10, _Appointment.Subject.Length - 1)
        wStartHour = Format(_Appointment.DateStart, "Short Time")
        wEndHour = Format(_Appointment.DateEnd, "Short Time")

        wSubject = String.Format("({0} - {1}) ", wStartHour, wEndHour)
        If wSubject.Length + _Appointment.Subject.Length - 2 > 30 Then
            lblSubject.Text = String.Concat(wSubject, _Appointment.Subject).Substring(0, 30) + "..."
        Else
            lblSubject.Text = String.Concat(wSubject, _Appointment.Subject)
        End If

        If _Appointment.Description.Length - 1 > 30 Then
            lblDescription.Text = String.Concat(_Appointment.Description.Substring(0, 30), "...")
        Else
            lblDescription.Text = _Appointment.Description
        End If

    End Sub

    Private Sub Label_DoubleClick(sender As System.Object, e As System.EventArgs) Handles lblSubject.DoubleClick, lblDescription.DoubleClick
        Dim wAptController As AppointmentController = Nothing
        Dim wFrmApt As frmAppointmentViewer = New frmAppointmentViewer(_Appointment, frmAppointmentViewer.Mode.Preview)

        wFrmApt.ShowDialog()
        If wFrmApt.IsDiscarded() Then
            wAptController = New AppointmentController
            wAptController.Delete(_Appointment.Id)
            Me.Dispose()
        End If
    End Sub

#End Region

#Region "<< -Methods- >>"
    Public Sub New(ByVal pAppointment As AppointmentBE)
        InitializeComponent()
        _Appointment = pAppointment
    End Sub

    Public Sub Discard()
        Dim wAptController As AppointmentController = New AppointmentController
        wAptController.Delete(_Appointment.Id)
        Me.Dispose()
    End Sub
#End Region

End Class
